package service

import (
	"fmt"
	"goapp-web-server/app/models"
	"goapp-web-server/app/utils/orm"
)

type SysRoleService interface {
	GetAll() ([]models.SysRole, error)
	GetByID(id int64) models.SysRole
}

func NewRoleService() SysRoleService {
	return new(roleService)
}

type roleService struct {
}

// role list
func (s *roleService) GetAll() ([]models.SysRole, error) {
	engine := orm.Engine
	list := make([]models.SysRole, 0)
	err := engine.Table("sys_role").
		Select(`sys_role.*`).
		Where("sys_role.deleted_at is NULL").
		Limit(10, 0).
		Find(&list)
	if err != nil {
		fmt.Println("error:", err)
		return nil, err
	}
	return list, nil
}

// get role by id
func (s *roleService) GetByID(id int64) models.SysRole {
	material := models.SysRole{}
	fmt.Println(material.Name)
	return material
}
